package com.molichuxing.job;

import com.molichuxing.service.CarJobService;
import com.xxl.job.core.biz.model.ReturnT;
import com.xxl.job.core.handler.IJobHandler;
import com.xxl.job.core.handler.annotation.JobHandler;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;

@JobHandler(value = "carHandler")
@Component
public class CarHandler extends IJobHandler {
    private static final Logger logger = LoggerFactory.getLogger(CarHandler.class);

    @Resource
    private CarJobService carJobService;

    public CarHandler() {
        super();
    }

    @Override
    public void init() {
        super.init();
    }

    @Override
    public void destroy() {
        super.destroy();
    }

    @Override
    public ReturnT<String> execute(String s) throws Exception {
        ReturnT<String> returnT = ReturnT.SUCCESS;
        logger.info("==============车辆定时任务start================");
        try {
            boolean result = carJobService.cacheAllCars();
            if (!result) {
                returnT = ReturnT.FAIL;
            }
            returnT.setContent("车辆定时任务结果result：" + result);
        } catch (Exception e) {
            logger.error("车辆定时任务异常", e);
            returnT = ReturnT.FAIL;
        }
        logger.info("==============车辆定时任务end================");
        return returnT;
    }

}
